<?php

/**
 * Description of AddConferenceThesis
 * 添加会议论文内容
 * 
 * @author ddj
 */
class AddConferenceThesisInfo extends AddInformation{
    private $confThesis;
    private $queryStr;
    
    function __construct( $confThesis=null) {
        $this->confThesis = $confThesis;
        $this->queryStr = sprintf('insert into ConferenceThesis(name, ownerAuthor, '
                    . 'responsibleAuthor, conferenceCorpusName, date, searchType, '
                    . 'searchID, recommendLevel, auditingState)'
                    . 'values ("%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s", "%s")',
                    $this->confThesis->name, $this->confThesis->ownerAuthor,
                    $this->confThesis->responsibleAuthor, 
                    $this->confThesis->conferenceCorpusName,
                    $this->confThesis->date,
                    $this->confThesis->searchType,
                    $this->confThesis->SearchID,
                    $this->confThesis->recommendLevel,
                    $this->confThesis->auditingState
            );
    }

    public function add( $linkIdentify ) {
        if($this->check()){
            if($this->addInfo($this->queryStr, $linkIdentify)){
                return true;
            }
            return false;
        }
    }
    
    /* 检查数据是否合格 */
    function check(){
        if($this->confThesis==NULL){
            return false;
        }
        /* 检查是否为空字符串 */
        foreach (AttributesName::$conferenceThesis as $value) {
            if($this->confThesis->$value==""){
                return false;
            }
        }
        /* 检查是否符合字符串要求 */
        /* 日期 */
        $timePattern = '/[0-9]{4}\-[0-9]{2}/';       // 日期的正则表达式模式
        if( preg_match($timePattern, $this->confThesis->date)==0 ){
            return false;
        }
        return true;
    }

}